﻿<cfscript>
/** 
* ORM TaskTimeTable
* 
* @hint "Hibernate persistenter t_task_timetable. 教学任务上课时间地点占用情况表" 
* 
*/ 

component 
	displayname="public.service.orm.senate.TaskTimeTable" 
	output=false 
	persistent=true 
	selectBeforeUpdate=true dynamicInsert=true dynamicUpdate=true 
	cacheuse="Transactional" 
	entityname="TaskTimeTable" 
	table="t_task_timetable"
	{

	property type="string" name="TaskTimeID" column="tasktime_id" fieldtype="id" generator="assigned" hint="教学班上课时间编号";

	property type="string" name="TimeIndex" column="tidx" hint="上课时间序列";
	property type="string" name="WeekIndex" column="widx" hint="周次序列";

	property type="string" name="WeekDay" column="wdidx" hint="星期几";
	property type="numeric" name="CellStart" column="cellidx" hint="起点节次";
	property type="numeric" name="CellLength" column="cellrelay" hint="使用节次长度";

	property type="string" name="TaskClassRoom" column="taskclsroom" hint="上课地点";
	property type="string" name="TaskClassTime" column="tasktime" hint="上课时间";
	property type="string" name="TaskWeek" column="task_week" hint="上课周次";

	property name="TaskArrange" fieldtype="many-to-one" fkcolumn="task_id" cfc="TaskArrange"  hint="排课教学任务";

	/**
	* @hint "生成排课时间序号"
	* 
	* @TaskArrange "排课教学任务"
	*/
	public string function getTimeIDX( required TaskArrange ) output=false {
		
		/* 
			排课时间序号规则 3位代码
		*/
		var nextID = numberFormat(1, "0__");
		
		var checkArray = ORMExecuteQuery("select TimeIndex from TaskTimeTable 
											where 
											TaskArrange = :task 
											order by TimeIndex desc", {task=arguments.TaskArrange}, { maxResults=1 });
		if (arrayLen(checkArray)) {
			/* 创建一个追加id */
			nextID = numberFormat((checkArray[1] + 1), "0__");
		}

		return nextID;
		
	}

	/**
	* @hint "自定义主键规则"
	* 
	* @TaskArrange "排课教学任务"
	* @TimeIndex "上课时间序列"
	*/
	public string function getID( required TaskArrange, required string TimeIndex ) output=false {
		
		var nextID = arguments.TaskArrange.getTaskID() & "," & arguments.TimeIndex;

		/* 
			主键生成规则 
			
			教学班上课时间编号22位 18位教学任务号 , 3位时间序号

			Unique: TASK_ID, TIDX
		*/
		return nextID;
	}
	
}

</cfscript>